40923121

  • Home
    • Site Map
    • reveal
    • blog
  • About
  • Develop
  • 作業
    • 40923121 hw1
      • PCH7 Expansion Card Audio Video and Storage
      • Expansion Slots
      • PCI PCI X Slots
      • Summary
      • PCI Express  PCIe  Expansion Slots
      • AMR and CNR Slots
      • Overclocking
      • Choosing a Processor
      • CPU Cache
      • Video Output
      • Storage Devices  Optical Drives
      • Storage Devices  External Devices
      • Storage Devices  Legacy Devices
      • 擴展插槽
      • PCI   PCI-X插槽
      • 概要
      • PCI Express PCIe 擴展插槽
      • AMR和CNR插槽
      • 超頻
      • 選擇處理器
      • CPU緩存
      • 視頻輸出
      • 存儲設備 光盤驅動器
      • 存儲設備 外部設備
      • 存儲設備 舊版設備
      • Overview
      • Heat Sources
      • Heat Effects
      • Heat Reduction
      • Active Air Cooling
      • Passive Air Cooling
      • Liquid Cooling
      • CPU Cooling
      • Case Fans
      • Liquid Cooling Installation
      • 總覽
      • 熱源
      • 熱效應
      • 減少熱量
      • 主動風冷
      • 被動風冷
      • 液體冷卻
      • CPU散熱
      • 機箱風扇
      • 液體冷卻 安裝
    • hw2
    • hw3
      • Discussion-1
      • Sets
      • Features of sets
      • In Python
      • 討論區-1
      • 集的特徵
      • 在Python中
      • Discussion-2
      • More string things
      • Splitting strings
      • Joining strings
      • 討論區-2
      • 更弦的東西
      • 分割字符串
      • 連接字符串
      • Discussion-3
Features of sets << Previous Next >> 討論區-1

In Python

In Python, you make and use a set with the set() keyword. For example:

  names = set()
  names.add("Michele")
  names.add("Robin")
  names.add("Michele")
  print(names)

And the output will be;

  set(['Michele', 'Robin'])

You can do to a set almost anything you can do to a list (except ask for things like “the third element”). See the Python documentation about sets to get a full list of things you can do to sets.

You can convert from a list to a set and a set to a list pretty easily:

  names = ["Michele", "Robin", "Sara", "Michele"]
  names = set(names)
  names = list(names)
  print(names)

And the result of this will be:

  ['Michele', 'Robin', 'Sara']

14 列出刪除重複項
練習14 和解決方案

編寫一個包含一個列表並返回一個新列表的程序(函數!),該列表包含第一個列表的所有元素減去所有重複項。

附加功能:

  • 編寫兩個不同的函數來執行此操作-一個使用循環並構造一個列表,另一個使用集合。
  • 返回並使用集合進行練習5,然後使用其他函數編寫解決方案。

Features of sets << Previous Next >> 討論區-1

Copyright © All rights reserved | This template is made with by Colorlib